package com.qianlou.controller;

import com.qianlou.common.result.BaseResponse;
import com.qianlou.pojo.bo.CandidateBO;
import com.qianlou.service.CandidateService;
import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/candidate")
public class CandidateController {


    @Resource
    private CandidateService candidateService;

    @PostMapping("/createOrUpdate")
    public BaseResponse createOrUpdate(@RequestBody @Valid CandidateBO candidateBO) {
        candidateService.createOrUpdate(candidateBO);
        return BaseResponse.ok();
    }

    @GetMapping("/list")
    public BaseResponse list(@RequestParam("realName") String realName,
                             @RequestParam("mobile") String mobile,
                             @RequestParam("page") Integer page,
                             @RequestParam("pageSize") Integer pageSize) {
        return BaseResponse.ok(candidateService.selectCandidateList(realName, mobile, page, pageSize));
    }

    @PostMapping("/delete")
    public BaseResponse delete(@RequestParam("candidateId") String candidateId) {
        candidateService.removeById(candidateId);
        return BaseResponse.ok();
    }

    @GetMapping("/detail")
    public BaseResponse detail(@RequestParam("candidateId") String candidateId) {
        return BaseResponse.ok(candidateService.getById(candidateId));
    }



}